<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use think\response\Json;

class Community extends Model
{
    protected $table = 'community';//表名 小区表
    protected $fillable = ['community_name', 'community_address', 'community_developers', 'community_mobile', 'community_person', 'community_person_mobile'];//白名单
    use  SoftDeletes;

    public function indexPage($page, $limit, $propertyId)
    {
        $start = ($page - 1) * $limit;
        $res = $this->where('property_id', $propertyId)->offset($start)->limit($limit)->orderBy('id', 'desc')->get();
        return $res;
    }

    public function indexPageLike($page, $limit, $condition, $propertyId)
    {
        $start = ($page - 1) * $limit;
        $query = 'SELECT * FROM `community` WHERE `property_id`= ? AND CONCAT(`community_name`,`community_address`,`community_developers`,`community_mobile`,`community_person`,`community_person_mobile`) LIKE ?  ORDER BY(id) desc  limit ?,?';
        $param = '%' . $condition . '%';
        $res = DB::select($query, array($propertyId, $param, $start, $limit));
        return json_decode(json_encode($res), true);
    }
}
